package com.tf_cut.backend.cpm.service;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.tf_cut.backend.common.pojo.PageInfo;
import com.tf_cut.backend.cpm.vo.CpmInsideTransComVo;
import com.tf_cut.backend.mapper.CpmInsideTransMapper;

@Service
@Transactional
public class CpmInsideTransComServiceImpl implements CpmInsideTransComService {

    @PersistenceContext
    private EntityManager em;
    
    @Autowired
    private CpmInsideTransMapper cpmInsideTransMapper;
    
    @Override
    public PageInfo<CpmInsideTransComVo> findQuarterCommission(CpmInsideTransComVo vo){
    	PageHelper.startPage(vo.getPage() , vo.getRows());
    	List<CpmInsideTransComVo> listVo = cpmInsideTransMapper.findQuarterCommission(vo);
		com.github.pagehelper.PageInfo<CpmInsideTransComVo> pageinfo = new com.github.pagehelper.PageInfo<>(listVo);
		
		PageInfo<CpmInsideTransComVo> returnPageInfo = new PageInfo<>();
		returnPageInfo.setPage(pageinfo.getPageNum());//页码
		returnPageInfo.setPageSize(pageinfo.getPageSize());//页面大小
		returnPageInfo.setRows(pageinfo.getList());//分页结果
		returnPageInfo.setRecords((int)pageinfo.getTotal());//总记录数
		returnPageInfo.setTotal(pageinfo.getPages());//总页数
		return returnPageInfo;
    }
    
    @Override
    public void updatePayQuarter(String val, String type){
    	String[] ids = val.split(","); 
    	cpmInsideTransMapper.updatePayQuarter(ids,type);
    }
}
